package br.com.teste.manager.tarefa.impl;

import br.com.teste.entity.Tarefa;
import br.com.teste.manager.AbstractTesteManager;
import br.com.teste.manager.tarefa.TarefaManager;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import static com.google.code.liquidform.LiquidForm.*;

public class JpaTarefaManagerImpl extends AbstractTesteManager implements TarefaManager {

    @Override
    @Transactional
    public void salvar(Tarefa tarefa) {
        getEntityManager().merge(tarefa);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Tarefa> listar() {
        Tarefa t = alias(Tarefa.class, "t");
        String ql = select(t).from(Tarefa.class).as(t).toString();
        return getEntityManager().createQuery(ql).getResultList();
    }

    @Override
    @Transactional(readOnly = true)
    public Tarefa buscarPeloId(Long id) {
        return getEntityManager().find(Tarefa.class, id);
    }
}
